package com.ruoyi.common.core.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class MyTree{
    /** 节点ID */
    private Long id;

    /** 节点父ID */
    private Long pId;

    /** 节点名称 */
    private String name;

    /** 节点标题 */
    private String title;

    /** 父id **/
    private Long parentId;

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public Long getParentId() {
        return parentId;
    }

    private List<MyTree> children;

    public void setId(Long id) {
        this.id = id;
    }

    public void setpId(Long pId) {
        this.pId = pId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String setChildren(List<MyTree> children) {
        this.children = children;
        return "123";
    }

    public Long getId() {
        return id;
    }

    public Long getpId() {
        return pId;
    }

    public String getName() {
        return name;
    }

    public String getTitle() {
        return title;
    }

    public List<MyTree> getChildren() {
        return children;
    }

    @Override
    public String toString() {
        return "MyTree{" +
                "id=" + id +
                ", pId=" + pId +
                ", name='" + name + '\'' +
                ", title='" + title + '\'' +
                ", children=" + children +
                '}';
    }

    static public List<MyTree> CombinationTree(Long parentId, List<MyTree> list) {
        List<MyTree> ProjectList1 = new ArrayList<>();

//      为一级项目添加内容
        ProjectList1= list.stream()
                .filter(pro -> pro.getpId() == parentId)
                .collect(Collectors.toList());

        if (ProjectList1.size() == 0) {
            return null;
        }
        //      为二级项目添加内容,添加一级项目中list的内容
        ProjectList1.stream()
                .forEach(child ->child.setChildren(CombinationTree(child.getId(), list)));

        return ProjectList1;
    }
}
